1 <!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8">
5 <meta http-equiv=
"Content-Style-Type" content=
"text/css">
7 <meta name=
"Generator" content=
"Cocoa HTML Writer">
8 <meta name=
"CocoaVersion" content=
"1038.25">
9 <style type=
"text/css">
10 p
.p1
{margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica
}
11 p
.p2
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
; min-height: 14.0px}
12 p
.p3
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
}
13 p
.p4
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #0021be}
14 p
.p5
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
}
15 p
.p6
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; min-height: 12.0px}
16 p
.p7
{margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Helvetica
}
17 p
.p8
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #b2140d}
18 p
.p9
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #2c6f14}
19 p
.p10
{margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica
; color: #0000ee}
20 span
.s1
{color: #000000}
21 span
.s2
{color: #0021be}
22 span
.s3
{color: #2c6f14}
23 span
.s4
{text-decoration: underline
; color: #002ff3}
24 span
.s5
{text-decoration: underline
}
25 span
.s6
{font: 12.0px Helvetica
}
26 span
.s7
{color: #0042e1}
27 span
.Apple-tab-span
{white-space:pre
}
31 <p class=
"p1"><b>Sequencing with Patterns
</b></p>
32 <p class=
"p2"><br></p>
33 <p class=
"p3">The previous section demonstrated how to use data routines to generate sequences of synthesis parameters. However, writing a routine with explicit yields is not a very convenient syntax. Since this is an essential part of creating computer music, we really need an easier way.
</p>
34 <p class=
"p2"><br></p>
35 <p class=
"p3">Patterns greatly simplify the use of data streams. A pattern is essentially a factory for a stream. The pattern objects includes the data you want to come out of the stream, and the type of pattern determines how the data will be streamed.
</p>
36 <p class=
"p2"><br></p>
37 <p class=
"p3">For example, we used this routine to output MIDI note numbers to play a couple of phrases from 'Over the Rainbow.'
</p>
38 <p class=
"p2"><br></p>
39 <p class=
"p4"><span class=
"s1">r =
</span>Routine
<span class=
"s1">({
</span></p>
40 <p class=
"p5"><span class=
"Apple-tab-span"> </span>[
60,
72,
71,
67,
69,
71,
72,
60,
69,
67].do({
<span class=
"s2">|midi|
</span> midi.yield });
</p>
42 <p class=
"p6"><br></p>
43 <p class=
"p5">while { (m = r.next).notNil } { m.postln };
</p>
44 <p class=
"p2"><br></p>
45 <p class=
"p3">With patterns, we can express the idea of a stream returning the same values, but more clearly and concisely. Because we don't have to write the yield explicitly, there is nothing in the pattern to distract attention from the data (which are the real concern in composition).
</p>
46 <p class=
"p2"><br></p>
47 <p class=
"p3"><b>Pseq
</b> (Pattern-sequence) means simply to spit out the values in the array one by one, in order, as many times as the second argument (here, only once).
</p>
48 <p class=
"p2"><br></p>
49 <p class=
"p5">p =
<span class=
"s2">Pseq
</span>([
60,
72,
71,
67,
69,
71,
72,
60,
69,
67],
1);
</p>
50 <p class=
"p5">r = p.asStream;
</p>
51 <p class=
"p5">while { (m = r.next).notNil } { m.postln };
</p>
52 <p class=
"p2"><br></p>
53 <p class=
"p3">Note that the Pseq is not streamable by itself, but it creates a stream (Routine) when you call asStream on it. This routine can then be used exactly like to any other routine -- the while loop used to read out the stream values is exactly the same for both, even though they are written differently.
</p>
54 <p class=
"p2"><br></p>
55 <p class=
"p3">Thus the 'Over the Rainbow' example could be rewritten, with less clutter:
</p>
56 <p class=
"p2"><br></p>
58 <p class=
"p5"><span class=
"s2">var
</span> midi, dur;
</p>
59 <p class=
"p5">midi =
<span class=
"s2">Pseq
</span>([
60,
72,
71,
67,
69,
71,
72,
60,
69,
67],
1).asStream;
</p>
60 <p class=
"p5">dur =
<span class=
"s2">Pseq
</span>([
2,
2,
1,
0.5,
0.5,
1,
1,
2,
2,
3],
1).asStream;
</p>
61 <p class=
"p6"><br></p>
62 <p class=
"p4">SynthDef
<span class=
"s1">(
</span><span class=
"s3">\smooth
</span><span class=
"s1">, {
</span>|freq =
440, sustain =
1, amp =
0.5|
</p>
63 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"s2">var
</span><span class=
"Apple-tab-span"> </span>sig;
</p>
64 <p class=
"p5"><span class=
"Apple-tab-span"> </span>sig =
<span class=
"s2">SinOsc
</span>.ar(freq,
0, amp) *
<span class=
"s2">EnvGen
</span>.kr(
<span class=
"s2">Env
</span>.linen(
0.05, sustain,
0.1), doneAction:
2);
</p>
65 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"s2">Out
</span>.ar(
0, sig !
2)
</p>
66 <p class=
"p5">}).send(s);
</p>
67 <p class=
"p6"><br></p>
68 <p class=
"p5">r =
<span class=
"s2">Task
</span>({
</p>
69 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"s2">var
</span><span class=
"Apple-tab-span"> </span>delta;
</p>
70 <p class=
"p5"><span class=
"Apple-tab-span"> </span>while {
</p>
71 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>delta = dur.next;
</p>
72 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>delta.notNil
</p>
73 <p class=
"p5"><span class=
"Apple-tab-span"> </span>} {
</p>
74 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s2">Synth
</span>(
<span class=
"s3">\smooth
</span>, [freq: midi.next.midicps, sustain: delta]);
</p>
75 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>delta.yield;
</p>
76 <p class=
"p5"><span class=
"Apple-tab-span"> </span>}
</p>
77 <p class=
"p5">}).play(quant:
<span class=
"s2">TempoClock
</span>.default.beats +
1.0);
</p>
79 <p class=
"p2"><br></p>
80 <p class=
"p7"><b>What else can patterns do?
</b></p>
81 <p class=
"p2"><br></p>
82 <p class=
"p3">The SuperCollider pattern library is large (over
120 classes, not including extension libraries), obviously beyond the scope of a tutorial to cover in depth. But some patterns you'll come back to again and again.
</p>
83 <p class=
"p2"><br></p>
84 <p class=
"p3">Many patterns take lists of values and return them in some order.
</p>
85 <p class=
"p2"><br></p>
86 <p class=
"p3"><b>Pseq(list, repeats, offset)
</b> -- return the list's values in order
</p>
87 <p class=
"p3"><b>Pshuf(list, repeats)
</b> -- scramble the list into random order
</p>
88 <p class=
"p3"><b>Prand(list, repeats)
</b> -- choose from the list's values randomly
</p>
89 <p class=
"p3"><b>Pxrand(list, repeats)
</b> -- choose randomly, but never return the same list item twice in a row
</p>
90 <p class=
"p3"><b>Pwrand(list, weights, repeats)
</b> -- like Prand, but chooses values according to a list of probabilities/weights
</p>
91 <p class=
"p2"><br></p>
92 <p class=
"p3">Other patterns generate values according to various parameters. In addition to these basic patterns, there is a whole set of random number generators that produce specific distributions, and also chaotic functions.
</p>
93 <p class=
"p2"><br></p>
94 <p class=
"p3"><b>Pseries(start, step, length)
</b> -- arithmetic series, e.g.,
1,
2,
3,
4,
5</p>
95 <p class=
"p3"><b>Pgeom(start, grow, length)
</b> -- geometric series, e.g.,
1,
2,
4,
8,
16</p>
96 <p class=
"p3"><b>Pwhite(lo, hi, length)
</b> -- random number generator, uses rrand(lo, hi) -- equal distribution
</p>
97 <p class=
"p3"><b>Pexprand(lo, hi, length)
</b> -- random number generator, uses exprand(lo, hi) -- exponential distribution
</p>
98 <p class=
"p2"><br></p>
99 <p class=
"p3">Other patterns modify the output of value patterns. These are called FilterPatterns.
</p>
100 <p class=
"p2"><br></p>
101 <p class=
"p3"><b>Pn(pattern, repeats)
</b> -- repeat the pattern as many times as repeats indicates
</p>
102 <p class=
"p3"><b>Pstutter(n, pattern)
</b> -- repeat individual values from a pattern
<i>n
</i> times.
<i>n
</i> may be a numeric pattern itself.
</p>
103 <p class=
"p2"><br></p>
104 <p class=
"p3">You can use patterns inside of other patterns. Here, we generate random numbers over a gradually increasing range. The upper bound on the random number generator is a stream that starts at
0.01, then proceeds to
0.02,
0.03 and so on, as the plot shows clearly.
</p>
105 <p class=
"p2"><br></p>
106 <p class=
"p5">p =
<span class=
"s2">Pwhite
</span>(
0.0,
<span class=
"s2">Pseries
</span>(
0.01,
0.01,
<span class=
"s2">inf
</span>),
100).asStream;
</p>
107 <p class=
"p8"><span class=
"s1"><span class=
"Apple-tab-span"> </span></span>// .all pulls from the stream until it returns nil
</p>
108 <p class=
"p8"><span class=
"s1"><span class=
"Apple-tab-span"> </span></span>// obviously you don't want to do this for an 'inf' length stream!
</p>
109 <p class=
"p5">p.all.plot;
</p>
110 <p class=
"p2"><br></p>
111 <p class=
"p3">Or, for another example, if you want to order a set of numbers randomly so that all numbers come out before a new order is chosen, use Pn to repeat a Pshuf.
</p>
112 <p class=
"p2"><br></p>
113 <p class=
"p5">p =
<span class=
"s2">Pn
</span>(
<span class=
"s2">Pshuf
</span>([
1,
2,
3,
4,
5],
1),
<span class=
"s2">inf
</span>).asStream;
</p>
114 <p class=
"p8"><span class=
"s1">p.nextN(
15);
<span class=
"Apple-tab-span"> </span></span>// get
15 values from the pattern's stream
</p>
115 <p class=
"p2"><br></p>
116 <p class=
"p3">This is just a taste, meant to illustrate the kinds of flexibility you can get with patterns. As with any rich and adaptable structure, the best way is to start with simple cases and gradually extend into more complicated setups.
</p>
117 <p class=
"p2"><br></p>
118 <p class=
"p7"><b>Playing notes with a pattern: Pbind
</b></p>
119 <p class=
"p2"><br></p>
120 <p class=
"p3">Not only can patterns produce data for notes, but they can also play the notes themselves. 'Over the Rainbow' again.
</p>
121 <p class=
"p2"><br></p>
123 <p class=
"p4">SynthDef
<span class=
"s1">(
</span><span class=
"s3">\smooth
</span><span class=
"s1">, {
</span>|freq =
440, sustain =
1, amp =
0.5|
</p>
124 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"s2">var
</span><span class=
"Apple-tab-span"> </span>sig;
</p>
125 <p class=
"p5"><span class=
"Apple-tab-span"> </span>sig =
<span class=
"s2">SinOsc
</span>.ar(freq,
0, amp) *
<span class=
"s2">EnvGen
</span>.kr(
<span class=
"s2">Env
</span>.linen(
0.05,
<span class=
"s2">sustain
</span>,
0.1), doneAction:
2);
</p>
126 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"s2">Out
</span>.ar(
0, sig !
2)
</p>
127 <p class=
"p5">}).add;
</p>
129 <p class=
"p6"><br></p>
131 <p class=
"p5">p =
<span class=
"s2">Pbind
</span>(
</p>
132 <p class=
"p8"><span class=
"s1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// the name of the SynthDef to use for each note
</p>
133 <p class=
"p9"><span class=
"s1"><span class=
"Apple-tab-span"> </span></span>\instrument
<span class=
"s1">,
</span>\smooth
<span class=
"s1">,
</span></p>
134 <p class=
"p8"><span class=
"s1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// MIDI note numbers -- converted automatically to Hz
</p>
135 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"s3">\midinote
</span>,
<span class=
"s2">Pseq
</span>([
60,
72,
71,
67,
69,
71,
72,
60,
69,
67],
1),
</p>
136 <p class=
"p8"><span class=
"s1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>// rhythmic values
</p>
137 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"s3">\
</span><span class=
"s2">dur
</span>,
<span class=
"s2">Pseq
</span>([
2,
2,
1,
0.5,
0.5,
1,
1,
2,
2,
3],
1)
</p>
138 <p class=
"p5">).play;
</p>
140 <p class=
"p2"><br></p>
141 <p class=
"p3">The first thing to notice is how short, concise and clean the syntax is. Nothing is extra; it focuses all your attention on what is supposed to play and minimizes distractions from program logic.
</p>
142 <p class=
"p2"><br></p>
143 <p class=
"p3">The
<a href=
"../../Streams-Patterns-Events/Streams.html"><span class=
"s4">Streams
</span></a> documentation explains how all of this works in detail. The high-level overview goes like this:
</p>
144 <p class=
"p2"><br></p>
145 <p class=
"p3">- The Pbind pattern generates Event objects, which contain names and values describing how the note is supposed to sound.
</p>
146 <p class=
"p2"><br></p>
147 <p class=
"p3">- It does this by reading through the 'name, pattern' pairs, getting values from each pattern stream in turn and adding the values to the result Event.
</p>
148 <p class=
"p2"><br></p>
149 <p class=
"p3">- Then the event is played. It interprets the values according to a set of defaults and rules encoded within the event prototype and performs an action in response. The default action is to play a new synth on the server. You can choose from several other actions defined in the default event prototype, which are documented in the Streams series of help files.
</p>
150 <p class=
"p2"><br></p>
151 <p class=
"p3">- To play the synth, the event needs to know which values to pass as arguments to the server. SuperCollider can store information about a synthdef into a library of synthdef descriptions using the
<b>add
</b> method.
</p>
152 <p class=
"p2"><br></p>
153 <p class=
"p3">- The delta value in the event tells SuperCollider how long to wait until playing the next event.
</p>
154 <p class=
"p2"><br></p>
155 <p class=
"p3">An introductory tutorial cannot cover all the possibilities. Learning a set of core pattern classes is important; the
<a href=
"../../Streams-Patterns-Events/A%20Practical%20Guide/PG_01_Introduction.html"><span class=
"s4">Practical Guide to Patterns
</span></a> help file series is a more comprehensive introduction. Pattern manipulations, and ways to combine or nest patterns, open up the field to nearly every compositional need.
</p>
156 <p class=
"p2"><br></p>
157 <p class=
"p3">For example, we can generate a rhythmic (but not necessarily metric) bassline by choosing randomly from a set of Pbind sequences. (Some of these will use Pmono, which is a variant of Pbind designed to play monophonic synth lines.) While this is a bigger block of code, its structure is fairly simple and it brings together several concepts introduced in the sequencing tutorials. Note that the quant argument to play is used to keep a couple of distinct sequences together on the beat.
</p>
158 <p class=
"p2"><br></p>
159 <p class=
"p3">Don't be intimidated by the bassline pattern. At a higher level, it reduces to
<b>Pxrand([a, b, c, d], inf)
</b>, which simply chooses items randomly without repeating any of them twice in a row. It happens that each item is an event pattern that plays a series of notes, but this doesn't matter to Pxrand. It just chooses an item, plays it through to the end, and then chooses the next, and so forth. Viewed this way, the pattern is an elegant expression of the idea of selecting phrases. The code representation is straightforward to relate to a musical conception.
</p>
160 <p class=
"p2"><br></p>
162 <p class=
"p4">SynthDef
<span class=
"s1">(
</span><span class=
"s3">\bass
</span><span class=
"s1">, {
</span>|freq =
440, gate =
1, amp =
0.5, slideTime =
0.17, ffreq =
1100, width =
0.15,
</p>
163 <p class=
"p4"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>detune =
1.005, preamp =
4|
</p>
164 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"s2">var
</span><span class=
"Apple-tab-span"> </span>sig,
</p>
165 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>env =
<span class=
"s2">Env
</span>.adsr(
0.01,
0.3,
0.4,
0.1);
<span class=
"Apple-tab-span"> </span></p>
166 <p class=
"p5"><span class=
"Apple-tab-span"> </span>freq =
<span class=
"s2">Lag
</span>.kr(freq, slideTime);
</p>
167 <p class=
"p5"><span class=
"Apple-tab-span"> </span>sig =
<span class=
"s2">Mix
</span>(
<span class=
"s2">VarSaw
</span>.ar([freq, freq * detune],
0, width, preamp)).distort * amp
</p>
168 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>*
<span class=
"s2">EnvGen
</span>.kr(env, gate, doneAction:
2);
</p>
169 <p class=
"p5"><span class=
"Apple-tab-span"> </span>sig =
<span class=
"s2">LPF
</span>.ar(sig, ffreq);
</p>
170 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"s2">Out
</span>.ar(
0, sig !
2)
</p>
171 <p class=
"p5">}).add;
</p>
172 <p class=
"p6"><br></p>
173 <p class=
"p5"><span class=
"s2">TempoClock
</span>.default.tempo =
132/
60;
</p>
174 <p class=
"p6"><br></p>
175 <p class=
"p5">p =
<span class=
"s2">Pxrand
</span>([
</p>
176 <p class=
"p4"><span class=
"s1"><span class=
"Apple-tab-span"> </span></span>Pbind
<span class=
"s1">(
</span></p>
177 <p class=
"p9"><span class=
"s1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>\instrument
<span class=
"s1">,
</span>\bass
<span class=
"s1">,
</span></p>
178 <p class=
"p9"><span class=
"s1"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span>\midinote
<span class=
"s1">,
36,
</span></p>
179 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s3">\dur
</span>,
<span class=
"s2">Pseq
</span>([
0.75,
0.25,
0.25,
0.25,
0.5],
1),
</p>
180 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s3">\legato
</span>,
<span class=
"s2">Pseq
</span>([
0.9,
0.3,
0.3,
0.3,
0.3],
1),
</p>
181 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s3">\amp
</span>,
0.5,
<span class=
"s3">\detune
</span>,
1.005</p>
182 <p class=
"p5"><span class=
"Apple-tab-span"> </span>),
</p>
183 <p class=
"p4"><span class=
"s1"><span class=
"Apple-tab-span"> </span></span>Pmono
<span class=
"s1">(
</span><span class=
"s3">\bass
</span><span class=
"s1">,
</span></p>
184 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s3">\midinote
</span>,
<span class=
"s2">Pseq
</span>([
36,
48,
36],
1),
</p>
185 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s3">\dur
</span>,
<span class=
"s2">Pseq
</span>([
0.25,
0.25,
0.5],
1),
</p>
186 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s3">\amp
</span>,
0.5,
<span class=
"s3">\detune
</span>,
1.005</p>
187 <p class=
"p5"><span class=
"Apple-tab-span"> </span>),
</p>
188 <p class=
"p4"><span class=
"s1"><span class=
"Apple-tab-span"> </span></span>Pmono
<span class=
"s1">(
</span><span class=
"s3">\bass
</span><span class=
"s1">,
</span></p>
189 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s3">\midinote
</span>,
<span class=
"s2">Pseq
</span>([
36,
42,
41,
33],
1),
</p>
190 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s3">\dur
</span>,
<span class=
"s2">Pseq
</span>([
0.25,
0.25,
0.25,
0.75],
1),
</p>
191 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s3">\amp
</span>,
0.5,
<span class=
"s3">\detune
</span>,
1.005</p>
192 <p class=
"p5"><span class=
"Apple-tab-span"> </span>),
</p>
193 <p class=
"p4"><span class=
"s1"><span class=
"Apple-tab-span"> </span></span>Pmono
<span class=
"s1">(
</span><span class=
"s3">\bass
</span><span class=
"s1">,
</span></p>
194 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s3">\midinote
</span>,
<span class=
"s2">Pseq
</span>([
36,
39,
36,
42],
1),
</p>
195 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s3">\dur
</span>,
<span class=
"s2">Pseq
</span>([
0.25,
0.5,
0.25,
0.5],
1),
</p>
196 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"s3">\amp
</span>,
0.5,
<span class=
"s3">\detune
</span>,
1.005</p>
197 <p class=
"p5"><span class=
"Apple-tab-span"> </span>)
</p>
198 <p class=
"p5">],
<span class=
"s2">inf
</span>).play(quant:
1);
</p>
200 <p class=
"p6"><br></p>
201 <p class=
"p8">// totally cheesy, but who could resist?
</p>
203 <p class=
"p4">SynthDef
<span class=
"s1">(
</span><span class=
"s3">\kik
</span><span class=
"s1">, {
</span>|preamp =
1, amp =
1|
</p>
204 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"s2">var
</span><span class=
"Apple-tab-span"> </span>freq =
<span class=
"s2">EnvGen
</span>.kr(
<span class=
"s2">Env
</span>([
400,
66], [
0.08], -
3)),
</p>
205 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>sig =
<span class=
"s2">SinOsc
</span>.ar(freq,
0.5pi, preamp).distort * amp
</p>
206 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>*
<span class=
"s2">EnvGen
</span>.kr(
<span class=
"s2">Env
</span>([
0,
1,
0.8,
0], [
0.01,
0.1,
0.2]), doneAction:
2);
</p>
207 <p class=
"p5"><span class=
"Apple-tab-span"> </span><span class=
"s2">Out
</span>.ar(
0, sig !
2);
</p>
208 <p class=
"p5">}).add;
</p>
209 <p class=
"p6"><br></p>
210 <p class=
"p8">// before you play:
</p>
211 <p class=
"p8">// what do you anticipate '\delta,
1' will do?
</p>
212 <p class=
"p5">k =
<span class=
"s2">Pbind
</span>(
<span class=
"s3">\instrument
</span>,
<span class=
"s3">\kik
</span>,
<span class=
"s3">\delta
</span>,
1,
<span class=
"s3">\preamp
</span>,
4.5,
<span class=
"s3">\amp
</span>,
0.32).play(quant:
1);
</p>
214 <p class=
"p6"><br></p>
215 <p class=
"p5">p.stop;
</p>
216 <p class=
"p5">k.stop;
</p>
217 <p class=
"p2"><br></p>
218 <p class=
"p2"><br></p>
219 <p class=
"p7"><b>Further reading:
</b></p>
220 <p class=
"p2"><br></p>
221 <p class=
"p10"><span class=
"s5"><a href=
"../../Streams-Patterns-Events/Streams.html">Streams
</a></span><span class=
"s1"><span class=
"Apple-tab-span"> </span><a href=
"../../Streams-Patterns-Events/Streams-Patterns-Events1.html"><span class=
"s6">Streams-Patterns-Events
</span></a><span class=
"Apple-tab-span"> </span><a href=
"../../Streams-Patterns-Events/A%20Practical%20Guide/PG_01_Introduction.html"><span class=
"s4">Practical Guide to Patterns
</span></a></span></p>
222 <p class=
"p2"><br></p>
223 <p class=
"p7"><b>Suggested exercises:
</b></p>
224 <p class=
"p2"><br></p>
225 <p class=
"p3">- Choose a familiar tune and write a Pbind for it, using any synthdef you like.
</p>
226 <p class=
"p3">- Add as many phrases as you wish to the bassline sequence in the previous example.
</p>
227 <p class=
"p2"><br></p>
228 <p class=
"p3">____________________
</p>
229 <p class=
"p2"><br></p>
230 <p class=
"p3">This document is part of the tutorial
<b>Getting Started With SuperCollider
</b>.
</p>
231 <p class=
"p2"><br></p>
232 <p class=
"p3">Click here to return to the table of Contents:
<a href=
"Getting Started With SC.html"><span class=
"s7">Getting Started With SC
</span></a></p>